package service4user

import (
	"Gin-Gorm-boke/boke_common/helper"
	"Gin-Gorm-boke/boke_common/oss"
	"github.com/gin-gonic/gin"
	"path"
)

func UploadImg(c *gin.Context) {
	file, err := c.FormFile("img")

	filename := file.Filename
	ext := path.Ext(filename)
	objectName := helper.GetUUID() + ext
	filePath, err := file.Open()
	if err != nil {
		c.JSON(200, gin.H{
			"code": 500,
			"msg":  "上传失败",
		})
		return
	}
	uploadFilePath, err := oss.UploadFile(objectName, filePath)
	if err != nil {
		c.JSON(200, gin.H{
			"code": 500,
			"msg":  "上传失败",
		})
		return
	}
	c.JSON(200, gin.H{
		"code": 200,
		"msg":  "操作成功",
		"data": uploadFilePath,
	})
}
